import {reqgetgoodsinfo,reqcartadd} from '../../request/api'
const initState = {
    list: [],
}
const types = {
    CHANGELIST: 'DETAIL_CHANGELIST'
}
const reducer = (state = initState, action) => {
    switch (action.type) {
        case types.CHANGELIST:
            return {
                ...state,
                list: action.arr
            }
            default:
                return state
    }
}
export const actions = {
    changelist: (arr) => ({
        type: types.CHANGELIST,
        arr
    }),

    reqlist:(id,history)=>(dispatch, getState)=>{
        reqgetgoodsinfo({id:id}).then(res=>{
           dispatch(actions.changelist(res.data.list))
            // history.push("/detail?id="+id)
            history.push("/detail")
        })  
    },
    reqshop:(id,history)=>(dispatch, getState)=>{
        let {uid}=getState().login.info
        console.log(id,uid);
        reqcartadd({
            uid:uid,
            type:1,
            goodsid:id,
            num:1
        }).then(res=>{
            history.push("/index/shop")
        })
        
    }
}

//导出数据
export const getlist = state => state.detail.list
export default reducer